
import time


from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

driver=webdriver.Edge()
driver.maximize_window() #浏览器最大化操作
driver.implicitly_wait(5)


driver.get("http://localhost/index.php/Home/user/login.html")
driver.find_element(By.CSS_SELECTOR,"#username").send_keys("13522221212")
driver.find_element(By.CSS_SELECTOR,"#password").send_keys("123456")
driver.find_element(By.CSS_SELECTOR,"#verify_code").send_keys("8888")
driver.find_element(By.CSS_SELECTOR,"a[name='sbtbutton']").click()
time.sleep(2)
ele=driver.find_element(By.CSS_SELECTOR,"body > div.nav-middan-z.p.home-index-head > div > div.m-navitems > ul > li:nth-child(2) > div > div.u-dt > span")
# # 1 通过ActionChains类创建鼠标对象
action=ActionChains(driver)
# # 2 执行鼠标操作事件   悬停
action.move_to_element(ele)  #鼠标的移动
# # 3 调用鼠标执行的方法
action.perform()
time.sleep(1)
ele=driver.find_element(By.CSS_SELECTOR,"body > div:nth-child(7) > div:nth-child(1) > div:nth-child(3) > ul:nth-child(1) > li:nth-child(2) > div:nth-child(1) > div:nth-child(2) > a:nth-child(2)")
# # 1 通过ActionChains类创建鼠标对象
ActionChains(driver).click(ele).perform()

ele2=driver.find_element(By.CSS_SELECTOR,"body > div.home-index-middle > div > div.home-main > div.ri-menu.fr > div > p")

ele2_text=ele2.text
# print(ele2[3:5])
# driver.find_element(By.CSS_SELECTOR,"body > div.home-index-middle > div > div.home-main > div.ri-menu.fr > div > div.goodpiece > a > span").click()
# driver.switch_to.frame(0)
# # 获取当前时间
# now=time.strftime("%H%M")
# driver.find_element(By.CSS_SELECTOR,"input[name='consignee']").send_keys("add")
# Select(driver.find_element(By.CSS_SELECTOR,"#province")).select_by_visible_text("山西")
ele3=driver.find_element(By.CSS_SELECTOR,"div[class='home-index-middle'] em:nth-child(1)").text
if int(ele2_text)+1==int(ele3):
    print("新增")
else:
    print("失败")
# 4 关闭浏览器驱动对象
time.sleep(30)  #代码暂停10s中
driver.quit()